//
//  WBTabBarViewController.swift
//  MyWeiBo
//
//  Created by mac on 15/3/4.
//  Copyright (c) 2015年 gpr. All rights reserved.
//

import UIKit

class WBTabBarViewController: UITabBarController {
    let titles = ["首页","消息","发现","我"]
    let images = ["tabbar_home","tabbar_message_center","tabbar_discover","tabbar_profile"]
    
    override class func initialize() {
        let tabbarItem = UITabBarItem.appearance()
        tabbarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.lightGrayColor()], forState: .Normal)
        tabbarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.setUpChildViewController()
 
    }
    
    func setUpChildViewController() {
        for i in 0..<self.viewControllers!.count {
            let childVC = self.viewControllers![i] as! UIViewController
            let title = titles[i]
            let imageName = images[i]
            let selectedImageName = imageName + "_selected"
            self.setUpTabBarButtonWithImage(childVC, title: title, imageName: imageName, selectedImageName: selectedImageName)
        }
    }
    
    func setUpTabBarButtonWithImage(childVC: UIViewController ,title: String, imageName: String, selectedImageName: String) {
        childVC.title = title as String
        childVC.tabBarItem.image = UIImage.originalImageWithName(imageName)
        childVC.tabBarItem.selectedImage = UIImage.originalImageWithName(selectedImageName)
    }

    class func WBMaiViewController() -> UITabBarController {
        let storyboard = UIStoryboard(name: "WBTabBarViewController", bundle: nil)
        return storyboard.instantiateInitialViewController() as! UITabBarController
    }

}
